﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for Per_ActionsRoles
    /// </summary>
    public class TblRoomManager : TblRoomManagerBase
    {
        public TblRoomManager()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static TblRoomManager CreateInstant()
        {
            return new TblRoomManager();
        }
        public List<TblRoomEntity> SelectTblRoomBy(int? Id, int? RoomTypeId, string TextId
                                                   , int? PageSize, int? PageIndex, out int TotalRow, string OrderByEx, string Collate)
        {
            TotalRow = 0;
            List<TblRoomEntity> lsresult = new List<TblRoomEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@TotalRow", TotalRow);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            if (Id.HasValue)
                ls.Add(new SqlParameter("@Id", Id.Value));
            if (RoomTypeId.HasValue)
                ls.Add(new SqlParameter("@RoomTypeId", RoomTypeId.Value));
            if (TextId != "")
                ls.Add(new SqlParameter("@TextId", TextId));           
            if (PageSize.HasValue && PageIndex.HasValue)
            {
                ls.Add(new SqlParameter("@PageSize", PageSize.Value));
                ls.Add(new SqlParameter("@PageIndex", PageIndex.Value));
            }
            if (!OrderByEx.Equals(string.Empty) && !Collate.Equals(string.Empty))
            {
                ls.Add(new SqlParameter("@OrderByEx", OrderByEx));
                ls.Add(new SqlParameter("@Collate", Collate));
            }
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblRoomBy", sqlparam);
            TotalRow = int.Parse(sqlparam[0].Value.ToString());
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblRoomEntity(dt.Rows[i]));
            return lsresult;
        }
        public List<TblRoomEntity> SelectTblRoomBy(int? Id, int? RoomTypeId, string TextId, string OrderByEx, string Collate)
        {
            int TotalRow = 0;
            return SelectTblRoomBy(Id, RoomTypeId, TextId, null, null, out TotalRow, OrderByEx, Collate);
        }
        public void SortTblRoom(int RoomTypeId)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@RoomTypeId", RoomTypeId));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SortTblRoom", sqlparam);
        }
        public List<TblRoomEntity> SelectTblRoomBy(int? Id, int? RoomTypeId, string RoomTypeTextId, string TextId
                                                   , int? PageSize, int? PageIndex, out int TotalRow, string OrderByEx, string Collate)
        {
            TotalRow = 0;
            List<TblRoomEntity> lsresult = new List<TblRoomEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@TotalRow", TotalRow);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            if (Id.HasValue)
                ls.Add(new SqlParameter("@Id", Id.Value));
            if (RoomTypeId.HasValue)
                ls.Add(new SqlParameter("@RoomTypeId", RoomTypeId.Value));
            if (TextId != "")
                ls.Add(new SqlParameter("@TextId", TextId));
            if (RoomTypeTextId != "")
                ls.Add(new SqlParameter("@RoomTypeTextId", RoomTypeTextId));
            if (PageSize.HasValue && PageIndex.HasValue)
            {
                ls.Add(new SqlParameter("@PageSize", PageSize.Value));
                ls.Add(new SqlParameter("@PageIndex", PageIndex.Value));
            }
            if (!OrderByEx.Equals(string.Empty) && !Collate.Equals(string.Empty))
            {
                ls.Add(new SqlParameter("@OrderByEx", OrderByEx));
                ls.Add(new SqlParameter("@Collate", Collate));
            }
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblRoomBy", sqlparam);
            TotalRow = int.Parse(sqlparam[0].Value.ToString());
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblRoomEntity(dt.Rows[i]));
            return lsresult;
        }
        public List<TblRoomEntity> SelectTblRoomBy(int? Id, int? RoomTypeId, string TextId, bool? IsVisible, bool? IsHome
                                                  , int? PageSize, int? PageIndex, out int TotalRow, string OrderByEx, string Collate)
        {
            TotalRow = 0;
            List<TblRoomEntity> lsresult = new List<TblRoomEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@TotalRow", TotalRow);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            if (Id.HasValue)
                ls.Add(new SqlParameter("@Id", Id.Value));
            if (RoomTypeId.HasValue)
                ls.Add(new SqlParameter("@RoomTypeId", RoomTypeId.Value));
            if (TextId != "")
                ls.Add(new SqlParameter("@TextId", TextId));            
            if (IsHome.HasValue)
                ls.Add(new SqlParameter("@IsHome", IsHome.Value));           
            if (IsVisible.HasValue)
                ls.Add(new SqlParameter("@IsVisible", IsVisible.Value));
            if (PageSize.HasValue && PageIndex.HasValue)
            {
                ls.Add(new SqlParameter("@PageSize", PageSize.Value));
                ls.Add(new SqlParameter("@PageIndex", PageIndex.Value));
            }
            if (!OrderByEx.Equals(string.Empty) && !Collate.Equals(string.Empty))
            {
                ls.Add(new SqlParameter("@OrderByEx", OrderByEx));
                ls.Add(new SqlParameter("@Collate", Collate));
            }
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblRoomBy", sqlparam);
            TotalRow = int.Parse(sqlparam[0].Value.ToString());
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblRoomEntity(dt.Rows[i]));
            return lsresult;
        }
    }
}
